function Node(value) {
    this.value = value;
    this.next = null;
}
const node1 = new Node(1);
const node2 = new Node(2);
const node3 = new Node(3);
const node4 = new Node(4);
const node5 = new Node(5);
const node6 = new Node(6);

node1.next = node2;
node2.next = node3;
node3.next = node4;
node4.next = node5
node5.next = node6;



function reverse(root) {
    if (root == null || root.next == null) return root;
    let res = reverse(root.next);
    root.next.next = root;
    root.next = null;
    return res;
}

function ergodicList(root) {
    console.log(root.value)
    if (root.next == null) {
        return
    } else {
        return ergodicList(root.next);
    }
}

const list = reverse(node1);
ergodicList(list);